package com.h2cloud;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.collections4.CollectionUtils;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @Package: com.h2cloud
 * @ClassName: Test1
 * @Author: wulongkai
 * @CreateTime: 2024/5/10 16:49
 * @Description:
 */
public class Test1 {

    public static void main(String[] args) {
        // JSON 文件路径（修改为你的文件路径）
        String filePath = "/Users/a58/Desktop/json.txt";

        // 初始化 ObjectMapper
        ObjectMapper objectMapper = new ObjectMapper();

        try {
            // 读取 JSON 文件
            JsonNode rootNode = objectMapper.readTree(new File(filePath));

            // 获取 data 节点
            JsonNode dataNode = rootNode.get("data");

            // 遍历 data 节点，提取字符串值
            if (dataNode != null && dataNode.isArray()) {
                for (JsonNode arrayNode : dataNode) {
                    if (arrayNode.isArray() && arrayNode.size() > 0) {
                        System.out.println(arrayNode.get(0).asText());
                    }
                }
            }
        } catch (IOException e) {
            System.err.println("读取或解析 JSON 文件时出错: " + e.getMessage());
        }
    }

//    public static void main(String[] args) throws InterruptedException {
//        Test1 t = new Test1();
//        new Thread(() -> {
//            t.print();
//        }).start();
//        new Thread(() -> {
//            t.print();
//        }).start();
//
//        System.out.println("main start");
//        Thread.sleep(200000);
//        System.out.println("main end");
//    }

    public void print() {
        try {
            System.out.println("start " + Thread.currentThread().getId());
            Thread.sleep(20000);
            System.out.println("end " + Thread.currentThread().getId());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
 }
